/*
 * Author: 黄荣基
 * Date: 2020-11-12 10:52:12
 * LastEditors: 黄荣基
 * LastEditTime: 2020-11-13 11:24:05
 */
import Vue from 'vue';
import VueI18n from 'vue-i18n';

Vue.use(VueI18n);

const loadLocaleMessages = () => {
  const locales = require.context('./lang', true, /[A-Za-z0-9-_,\s]+\.json$/i),
    messages = {};
  locales.keys().forEach(key => {
    const matched = key.match(/([A-Za-z0-9-_]+)\./i);
    if (matched && matched.length > 1) {
      const locale = String(matched[1]);
      messages[locale] = locales(key);
    }
  });
  return messages;
};

import { Locale } from 'vant';
// 引入英文语言包
import enUS from 'vant/es/locale/lang/en-US';

Locale.use('en-US', enUS);

export default new VueI18n({
  locale: process.env.VUE_APP_I18N_LOCALE || 'en',
  fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'en',
  messages: loadLocaleMessages()
});
